var express = require("express");
var router = express.Router();

/* GET users listing. */
/* 注册请求 */
router.post("/", function (req, res, next) {
  console.log(req.body);
  res.send("respond with a resource");
});

/* 登录请求 */
let jwt = require("jsonwebtoken");
router.get("/", function (req, res) {
  console.log(req.query);
  if (req.query.username == "admin" && req.query.password == "123456") {
    // 如果登录成功 返回jwt ，并且在token中存入用户名
    let token = jwt.sign({ username: "admin" }, "TaoShu", {
      expiresIn: "1day",
      algorithm: "HS256",
    });
    res.json({
      code: 200,
      msg: "登录成功",
    });
  } else {
    res.json({
      code: 500,
      msg: "登录失败",
    });
  }
});

module.exports = router;
